package cn.com.bluemoon.daps.sync.mapper;

import cn.com.bluemoon.daps.sync.entity.DapSyncDevEnvTask;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 开发同步库表任务表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2021-06-17
 */
public interface DapSyncDevEnvTaskMapper extends BaseMapper<DapSyncDevEnvTask> {

    @Select(" select * from dap_sync_dev_env_task \n" +
            " where id = \n" +
            "      (select id from dap_sync_dev_env_task " +
            "       where sync_env=1 and model_id = #{modelId} and table_id = #{tableId} " +
            "       order by create_time desc, update_time desc " +
            "       limit 1) " +
            " union all " +
            " select * from dap_sync_dev_env_task\n" +
            " where id = \n" +
            "      (select id from dap_sync_dev_env_task " +
            "       where sync_env=2 and model_id = #{modelId} and table_id = #{tableId} " +
            "       order by create_time desc, update_time desc " +
            "       limit 1) ")
    List<DapSyncDevEnvTask> queryDevSyncUnionAllTestSyncNewestOne(@Param("modelId") String modelId,
                                                                  @Param(("tableId")) String tableId);
}
